package com.bawei.mvvmzonghe.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bawei.mvvmzonghe.R;
import com.bawei.mvvmzonghe.databinding.ItemGoodsBinding;
import com.bawei.mvvmzonghe.entity.GoodsEntity;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @Author : yaotianxue
 * @Time : On 2023/9/14 10:33
 * @Description : GoodsAdapter
 */
public class GoodsAdapter extends RecyclerView.Adapter<GoodsAdapter.GoodsViewHolder> {
    private List<GoodsEntity.ListBean> mList;

    public GoodsAdapter(List<GoodsEntity.ListBean> list) {
        mList = list;
    }

    @NonNull
    @Override
    public GoodsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemGoodsBinding itemGoodsBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_goods,parent,false);
        return new GoodsViewHolder(itemGoodsBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull GoodsViewHolder holder, int position) {
        holder.mItemGoodsBinding.setGoods(mList.get(position));
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class GoodsViewHolder extends RecyclerView.ViewHolder{
        ItemGoodsBinding mItemGoodsBinding;
        public GoodsViewHolder( ItemGoodsBinding itemGoodsBinding) {
            super(itemGoodsBinding.getRoot());
            mItemGoodsBinding = itemGoodsBinding;
        }



    }

}
